﻿#ifndef LOGICCONTROLLER_H
#define LOGICCONTROLLER_H

#include <QObject>
#include <QSharedPointer>
#include <QFile>

#include "System/System.h"

#include "MiniZip/miniunz.h"
#include "Download/Download.h"

#include "DataType/CurrentPointStore.h"

#include "File/Xml/SceneListXml.h"
#include "File/Xml/RangeListXml.h"
#include "File/Xml/LogicControlXml.h"
#include "File/Xml/AutomaticXml.h"
#include "File/Xml/ModbusListXml.h"
#include "File/Xml/SWKNXListXml.h"

#include "Device/BaseDevice.h"
#include "Function/BaseFunc.h"
#include "Function/ControlKNXFunc.h"
#include "Function/ControlPointFunc.h"
#include "Function/UpdatePointFunc.h"
#include "Function/DownloadFileFunc.h"
#include "Function/DownloadFileResultFunc.h"
#include "Function/SendQueryDataFunc.h"
#include "Function/LogicCloudDataFunc.h"
#include "Function/Rs485SetTime.h"
#include "Protocol/ModbusProtocol.h"
#include "Device/ModbusDevice.h"
#include "Device/PointDevice.h"
class LogicController : public QObject
{
    Q_OBJECT
public:
    explicit LogicController(QObject *parent = 0);

    void registerDevice(BaseDevice* device);
    quint16 calculationData(quint16 choiceData,quint16 data);
    void TextRecord(QString data);
signals:
    void transferFuncSignal(QSharedPointer<BaseFunc> sharedFunc);


public slots:

    void transferFuncSlot(QSharedPointer<BaseFunc> sharedFunc);


private:
    QMap<QString,BaseDevice*> m_deviceList;
    typedef void (LogicController:: *HandlePointer)(QSharedPointer<BaseFunc>);
    QMap<int, HandlePointer> m_handleMap;

    QTimer *automaticTimer;
     QString lastTime;

    void registerFuncHandler(int functionCode,HandlePointer pHandle);
    void funcHandle(QSharedPointer<BaseFunc> sharedFunc);
    void controlPointFuncHandle(QSharedPointer<BaseFunc> sharedFunc);
    void controlKNXFuncHandle(QSharedPointer<BaseFunc> sharedFunc);
    void downloadFileFuncHandle(QSharedPointer<BaseFunc> sharedFunc);
    void LogicCloudDataFuncHandle(QSharedPointer<BaseFunc> sharedFunc);

private slots:
    void automaticSlot();
    void downloadFinisedSlot(PortStruct source,bool isSucceed, quint8 fileType, QString path);

};

#endif // LOGICCONTROLLER_H
